package com.example.demo.configuration;

import org.springframework.batch.core.Job;
import org.springframework.batch.test.JobLauncherTestUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;

/**
 * @author hc
 * @version 1.0
 * @date 2020/4/15 11:32
 * @description
 */
@Configuration
@Import({BatchConfig.class,HelloWorldJobConfig.class})
public class BatchTestConfig {
    @Autowired
    private Job helloWorlJob;

    @Bean
    JobLauncherTestUtils jobLauncherTestUtils() {
        //设置Job，把HelloWorldJobConfig类中的Bean注入到容器中
        JobLauncherTestUtils jobLauncherTestUtils =
                new JobLauncherTestUtils();
        //把job注入到测试工具类中并运行
        jobLauncherTestUtils.setJob(helloWorlJob);

        return jobLauncherTestUtils;
    }
}
